﻿
//Author: 张亚涛
//createtime:2011-10-13 10:35:35
//Description:

using System;
using System.Data;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Model;
using NS.DAL.Systems;


namespace DAL
{
    /// <summary>
    /// 该类提供了一系列操作 "CouponsTrade" 表的方法;
    /// </summary>
    public partial class CouponsTradeBase
    {
        #region .对本表的维护.
        #region select data
        /// <summary>
        /// 根据CouponsTrade表的TradeNo字段返回数据 
        /// </summary>
        /// <param name="TradeNo">商家订单号</param>
        /// <returns></returns>       
        public static CouponsTrade GetCouponsTradeByTradeNo(string tradeNo)
        {
            CouponsTrade couponsTrade = null;
            SqlDataReader reader = null;

            string sql = SQL_Select + "where [TradeNo] = @TradeNo";
            SqlParameter[] paras = new SqlParameter[]{
            new SqlParameter("@TradeNo",tradeNo)
            };
            reader = SQLHelper.ExecuteDataReader(sql, paras);
            if (reader.Read())
            {
                couponsTrade = new CouponsTrade(reader);
            }
            reader.Close();
            return couponsTrade;
        }
        /// <summary>
        /// 根据微信交易订单号返回已更新数据条数
        /// </summary>
        /// <param name="PayNo">微信交易订单号</param>
        /// <returns></returns>        
        public static int GetTradeCount(string PayNo)
        {
            string sql = "select count(TradeID) from [CouponsTrade] where PayNo='" + PayNo + "'";
            return int.Parse(SQLHelper.ExecuteScalar(sql, null));
        }

        #endregion
        #endregion


        #region .SQL语句汇总.
        /// <summary>
        /// 返回CouponsTrade表的所有数据 （SQL语句）
        /// </summary>
        /// <returns></returns>        
        public static string GetAllCouponsTrade_SQL(string tradeNo)
        {
            string strSQL = SQL_Select + " where TradeNo='"+tradeNo+"'";

            return strSQL;
        }
        #endregion
    }
}
